// index.js
// 获取应用实例
import http from '../../utils/http'

Page({
  data: {
    latitude: null,
    longitude: null,
    marker:[],
    // 未来3天的天气预报
    weathers: [],
    // 生活指数
    lifeStyle: [],
    iconList: [{
      id:0,
      name: '美食',
      iconPath:'/static/images/marker.png'
    },{
      id:1,
      name: '酒店',
      iconPath:'/static/images/marker.png'
    },{
      id:3,
      name: '加油站',
      iconPath:'/static/images/marker.png'
    },{
      id:4,
      name: '银行',
      iconPath:'/static/images/marker.png'
    },{
      id:5,
      name: '地铁站',
      iconPath:'/static/images/marker.png'
    },{
      id:6,
      name: '公厕',
      iconPath:'/static/images/marker.png'
    },{
      id:7,
      name: '公交站',
      iconPath:'/static/images/marker.png'
    },{
      id:8,
      name: '医院',
      iconPath:'/static/images/marker.png'
    }]
  },

  onLoad () {
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        this.setData({
          latitude : res.latitude,
          longitude : res.longitude,
          marker: [{
            id: 0,
            latitude: res.latitude,
            longitude : res.longitude,
            width: '80rpx',
            height: '80rpx',
            iconPath: '/static/images/location.png',
            callout: {
              'display': 'ALWAYS', 
              'fontSize': '30rpx', 
              'content': '当前所在位置',
              'padding': '8rpx', 
              'borderRadius': '4rpx'
            }
          }]
        })

        let location = res.longitude+","+res.latitude
        //  未来3天的天气预报
        http.get('/weather/3d', {
          location
        }).then(res => {
          this.setData({
            weathers: res.data.daily
          })
        })  
        
        // 生活指数
        const type = "1,2,3,4,5,6,7"
        http.get('/indices/1d',{
          location,
          type
        }).then(res=>{
          this.setData({
            lifeStyle: res.data.daily
          })
        })
      }
    })
    
  },
  goAroud: function (e) {
    wx.navigateTo({
      url: '/pages/index/map?keyWord='+e.currentTarget.dataset.keyword,
    })
  }

})
